﻿using DMSkin.WPF;
using MXComponent.Common.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MXComponent
{
    /// <summary>
    /// SoftRegWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SoftRegWindow : DMSkinSimpleWindow
    {
        private SoftRegister sregister = new SoftRegister();
        private IniHelp inifile;
        //private static string _intPath = Path.Combine(Application.StartupPath, "Setting.ini");
        //private  IniHelp inifile = new IniHelp(_intPath);
        //public static readonly string connectionString = inifile.IniReadValue("Setting", "connectionString");

        public SoftRegWindow()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.txtLicence.Text))
            {
                MessageBox.Show("注册码不能为空！");
                return;
            }
            if (this.txtLicence.Text.Trim() == sregister.GetRNum())
            {
                inifile.IniWriteValue("Setting", "SoftLicence", this.txtLicence.Text.Trim());
                MessageBox.Show("注册成功！");
                LoginWindow lw = new LoginWindow();
                lw.ShowDialog();
                this.Close();
            }
            else
            {
                MessageBox.Show("注册码错误！");
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Environment.Exit(0);
        }

        private void DMSkinSimpleWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.txtMachineCode.Text = sregister.GetMNum();
            //String appStartupPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            string _intPath = AppDomain.CurrentDomain.BaseDirectory + "Setting.ini";
            inifile = new IniHelp(_intPath);
            this.txtLicence.Focus();
        }
    }
}